﻿
@{
    ViewBag.Title = "商品";
}
@section CSS{
    <style>
        .table td .td_img {
            width: 80px;
            height: 80px;
            float: left;
            display: block;
        }

        .table td .td_title {
            width: 228px;
            height: 100px;
            float: left;
            margin-left: 5px;
        }

            .table td .td_title b {
                display: block;
                color: red;
                margin-top: 5px;
            }
    </style>
}
<!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                @ViewBag.tName
                <small>商品</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="active">@ViewBag.tName 商品</li>
            </ol>
        </section>
        <section style="display:none;">
            <div class="col-xs-12">
                <div class="box box-primary ">
                    <!-- form start -->
                    <form class="form-horizontal">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="title" class="col-sm-2 control-label">商品名称</label>
                                <div class="col-sm-2">
                                    <input type="text" class="form-control" id="title" placeholder="商品名称">
                                </div>
                                @*<label for="shopName" class="col-sm-2 control-label">店铺名称</label>
                                <div class="col-sm-2">
                                    <input type="text" class="form-control" id="shopName" placeholder="店铺名称">
                                </div>*@
                            </div>
                            <div class="form-group">
                                <label for="code" class="col-sm-2 control-label">商品编号</label>
                                <div class="col-sm-2">
                                    @*<input type="text" class="form-control" id="code" placeholder="商品编号">*@
                                </div>
                                <label for="category" class="col-sm-2 control-label">类别</label>
                                <div class="col-sm-2">
                                    <input type="text" class="form-control" id="category" placeholder="类别">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputUName" class="col-sm-2 control-label">商品状态</label>
                                <div class="col-sm-2">
                                    <select class="form-control" id="classSelect">
                                        <option value="-1">-请选择状态-</option>
                                        <option value="1">上架</option>
                                        <option value="0">下架</option>
                                    </select>
                                </div>
                                <label for="inputUName" class="col-sm-2 control-label">添加日期</label>
                                <div class="col-sm-2">
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" class="form-control pull-right" id="startTime">
                                    </div>
                                </div>
                                <label style="float:left;"> - </label>
                                <div class="col-sm-2">
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" class="form-control pull-right" id="endTime">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer ">
                            @*<button type="button" class="btn btn-primary btn-search center-block" id="btnSearch"><i class="fa fa-search"></i> 查询</button>*@
                            @*<button type="button" class="btn btn-danger" id="btnDelMul"><i class="fa fa-remove"></i> 批量删除</button>*@
                            @*<button type="button" class="btn btn-success" id="btnExport"><i class="fa fa-download"></i> 导出Excel</button>*@
                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>
            </div>
        </section>
        @*<section>
            <div class="col-xs-12 ">
                <div class="box box-primary">
                    <div class="box-body">
                        <div class="col-md-6 ">
                            <div class="info-box-content">
                                <span class="info-box-number"><small>总商品： </small>@ViewBag.goods_total（<small>普通</small>@ViewBag.goods1_total/<small>趣卡</small>@ViewBag.goods3_total/<small>免单</small>@ViewBag.goods2_total）</span>
                            </div>
                        </div>
                        <div class="col-md-2 ">
                            <div style="text-align:center;">
                                <span class="info-box-number">@ViewBag.goods_publish</span>
                                <span class="info-box-text" style="color:#c2c1c1;">出售中</span>
                            </div>
                        </div>
                        <div class="col-md-2 ">
                            <div style="border-left:1px #cdcdcd solid;text-align:center;">
                                <span class="info-box-number">@ViewBag.goods_no_stock</span>
                                <span class="info-box-text" style="color:#c2c1c1;">已售罄</span>
                            </div>
                        </div>
                        <div class="col-md-2 ">
                            <div style="border-left:1px #cdcdcd solid;text-align:center;">
                                <span class="info-box-number">@ViewBag.goods_no_publish</span>
                                <span class="info-box-text" style="color:#c2c1c1;">已下架</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>*@
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header my_search">
                            <input type="text" style="width:360px;" class="form-control" id="code" placeholder="商品编号/名称">
                            <select style="width:120px;" class="form-control" id="goodsType">
                                <option value="-1">-商品类型-</option>
                                <option value="1">普通商品</option>
                                <option value="3">趣卡专享</option>
                                <option value="2">合体免单</option>
                                <option value="4">1元购</option>
                            </select>
                            <button type="button" class="btn btn-default " id="btnSearch"><i class="fa fa-search"></i> 搜索</button>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="DataList" class="table table-bordered table-striped table-hover ">
                                <thead>
                                    <tr>
                                        <th>商品编号</th>
                                        <th width="330px">商品/价格</th>
                                        <th>库存</th>
                                        <th>总销量</th>
                                        <th>SKU</th>
                                        <th>创建时间</th>
                                        <th>排序</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                @*<tr>
                                    <td>10000251</td>
                                    <td>
                                        <img class="td_img" src="~/Content/img/wutuxiang.png" />
                                        <div class="td_title">
                                            <a>摩斯维oppo r11s手机壳 步步高R11splus手机保护套喷油磨砂硬壳薄</a>
                                            <b>￥1399.00</b>
                                        </div>
                                    </td>
                                    <td>1000</td>
                                    <td>9</td>
                                    <td>1</td>
                                    <td>2018-08-29<br />&nbsp;&nbsp;&nbsp;11:12:18</td>
                                    <td>99</td>
                                    <td><a>预览</a> - <a>查看SKU</a></td>
                                </tr>*@
                                <tbody></tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
<!-- /.content-wrapper -->
@section JS{
    <script>

    $(function () {
        //$("#DataList_filter").find("input").attr("placeholder","666");
            //初始化表格
            GenerateTable();
            //鼠标移动到该行变色
            $('.table-hover tbody').on('click', 'tr', function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                    console.log();
                }
                else {
                    u_table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });
            //搜索事件
            $("#btnSearch").on("click", function () {
                var datemin = $('#startTime').val();
                var datemax = $("#endTime").val();
                if ((datemin == null && datemax != null) || (datemin != null && datemax == null)) {
                    layer.msg('请把时间填充完整!', { icon: 1, time: 1000 });
                }
                else {
                    u_table.fnDestroy();
                    GenerateTable();
                }
            });

            $('#startTime').datepicker({
                autoclose: true
            });

            $('#endTime').datepicker({
                autoclose: true
            });
        });
        var tid=@ViewBag.tid;
        //生成表格
        function GenerateTable() {
            u_table = $('#DataList').dataTable({
                "lengthChange": false,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 10,
                "bProcessing": true,
                "bServerSide": true,
                "fnServerParams": function (aoData) {
                    var classSelect = $("#classSelect").val();
                    var datemin = $('#startTime').val();
                    var datemax = $("#endTime").val();
                    var title = $("#title").val();
                    //var shopName = $("#shopName").val();
                    var code = $.trim($("#code").val());
                    var category = $("#category").val();
                    var goodsType=$("#goodsType").val();
                    aoData.push(
                        { "name": "dateMin", "value": datemin },
                        { "name": "dateMax", "value": datemax },
                        { "name": "title", "value": title },
                        { "name": "shopName", "value": "" },
                        { "name": "code", "value": code },
                        { "name": "category", "value": category },
                        { "name": "type", "value": tid },
                        { "name": "goodsType", "value": goodsType },
                        { "name": "status", "value": classSelect }
                    );
                },
                "sAjaxSource": "/goods/GetGoodsListBySale",
                "aoColumns": [
                    { "mDataProp": 'id' },
                     {
                         "mDataProp": 'default_img', "mRender": function (data, type, full) {
                             //return data.length>6?(data.substring(0,6)+"…") :data;
                             return '<img class="td_img" src="'+(data==null||data==""?"/Content/img/wutuxiang.png":(domain+data))+'" />'
                                    +'<div class="td_title">'
                                    +'<a href = "/goods/EditGoods/' + full.id + '"  title="详情">'+full.name+'</a>'
                                    + '<b>￥'+full.sale_price+'</b>'
                                    +'</div>';
                         }
                     },
                    { "mDataProp": 'stock_count' },
                    {
                        "mDataProp": 'all_stock_count', "mRender": function (data, type, full) {
                            return ((data-full.stock_count)>0?(data-full.stock_count):"0");
                        }
                    },
                    { "mDataProp": 'sku_count' },

                    {
                        "mDataProp": 'add_time', "mRender": function (data, type, full) {
                            return moment(data).format("YYYY-MM-DD")+"<br />&nbsp;&nbsp;&nbsp;"+moment(data).format("HH:mm:ss");
                        }
                    },
                    { "mDataProp": 'sort' },
                    {
                        "mDataProp": 'id', "mRender": function (data, type, full) {
                            return ' <a href = "/goods/EditGoods/' + full.id + '"  title="详情">预览</a> '
                                //+'| <a  href = "/goods/GoodsPictures/' + full.id + '/0"  title="图片管理">滚动图片</a> |'
                                //+' <a href = "/goods/GoodsPictures/' + full.id + '/1"  title="图片管理">内容图片</a> |'
                                //+ ' <a href = "/goods/GoodsSpec/' + full.id + '"  title="规格管理">规格管理</a> |'
                                + '- <a href = "/goods/GoodsSku/' + full.id + '"  title="商品SKU">查看SKU</a> ' ;
                        }
                    }
                ]
            });
        }

        /*上架*/
        function goods_pass(obj, id) {
            layer.confirm('确定上架商品？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("上架").attr("onClick", "goods_noPass(this," + id + ")").attr("title", "点击下架").attr("class", "btn btn-success");
                            layer.msg('已上架', { icon: 6, time: 1000 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }
        /*下架*/
        function goods_noPass(obj, id) {
            layer.confirm('确定下架商品？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("下架").attr("onClick", "goods_pass(this," + id + ")").attr("title", "点击上架").attr("class", "btn btn-danger");
                            layer.msg('已下架', { icon: 5, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }

          /*设为新品*/
        function goods_new(obj, id) {
            layer.confirm('确定设为新品？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsNew",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("新品").attr("onClick", "goods_noNew(this," + id + ")").attr("title", "点击启用").attr("class", "btn btn-warning");
                            layer.msg('已设为新品', { icon: 6, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }
        /*取消新品*/
        function goods_noNew(obj, id) {
            layer.confirm('确定取消新品设置？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsNew",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("普通").attr("onClick", "goods_new(this," + id + ")").attr("title", "点击设为新品").attr("class", "btn btn-info");
                            layer.msg('已取消', { icon: 5, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }

          /*置顶*/
        function goods_top(obj, id) {
            layer.confirm('确定置顶？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsTop",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("置顶").attr("onClick", "goods_noTop(this," + id + ")").attr("title", "点击取消置顶").attr("class", "btn btn-warning");
                            layer.msg('已置顶', { icon: 6, time: 1000 });
                        }
                        else {
                            alert(data.info);
                        }
                    }
                });

            });
        }
        /*取消置顶*/
        function goods_noTop(obj, id) {
            layer.confirm('确定取消置顶？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsTop",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("常规").attr("onClick", "goods_top(this," + id + ")").attr("title", "点击置顶").attr("class", "btn btn-info");
                            layer.msg('已取消置顶', { icon: 5, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }
    </script>
}

